# Hide Wizard
$regPath = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\TeamViewer'
New-Item $regPath -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path $regPath -Name UnattendedAccessWizardShown -Value 1 -Type DWord -ErrorAction SilentlyContinue | Out-Null

# Install MSI
$tvopt_file = "C:\ProgramData\FileWave\Installers\TeamViewer\custom.tvopt"
$tvopt_example= "C:\ProgramData\FileWave\Installers\TeamViewer\example_custom.tvopt"

$options = '/i', "C:\ProgramData\FileWave\Installers\TeamViewer\TeamViewer_Host.msi", '/qn', 'DESKTOPSHORTCUTS=0', 'CUSTOMCONFIGID=65uhtxf'

# Use custom.tvopt if supplied
if (Test-Path $tvopt_file ) {
    $options += "SETTINGSFILE=`"$tvopt_file`""
} else {
    # Use example if existing
    if (Test-Path $tvopt_example ) {
        $options += "SETTINGSFILE=`"$tvopt_example`""
    }
}

echo "Installing TV with options: $options"

Start-Process 'msiexec.exe' -ArgumentList $options  -NoNewWindow -Wait -PassThru